package com.shopmall.controller;

import com.shopmall.pojo.BuyList;
import com.shopmall.pojo.GoodsInList;
import com.shopmall.service.BuyListServiceImpl;
import com.shopmall.service.GoodsInListServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
public class IncomeController {

    @Autowired
    GoodsInListServiceImpl goodsInListService;

    @Autowired
    BuyListServiceImpl buyListService;

    @RequestMapping("/income/income_all")
    public String income_all(Model model){
        List<GoodsInList> goodsInLists = goodsInListService.queryGoodsInListList();
        List<BuyList> buyLists = buyListService.queryBuyListList();
        int outcome=0;
        int income=0;
        for(GoodsInList i : goodsInLists){
            outcome=outcome+(i.getNum())*(i.getPrice_in());
        }
        for(BuyList j : buyLists){
            income+=(j.getNum())*(j.getPrice_out());
        }
        model.addAttribute("outcome_all",outcome);
        model.addAttribute("income_all",income);
        model.addAttribute("real_all",income-outcome);
        return "/income/income_all";
    }
}
